<?php
/**
 * wap 2.0 品牌商品列表
 */


$cache_id = sprintf('%X', crc32(__FILE__));

if (!$smarty->is_cached('brand_index.dwt', $cache_id))
{
	$brand_id = empty($_GET['id']) ? 0 : intval($_GET['id']);	// 品牌ID
	$cat_id = empty($_GET['cat_id']) ? 1 : intval($_GET['cat_id']);	// 分类ID

	$perpage = 40;
	$page = empty($_GET['page']) ? 1 : intval($_GET['page']);	// 页码

	$sort = empty($_GET['sort']) ? 0 : intval($_GET['sort']);	// 排序
	$filter_stock = empty($_GET['filter_stock']) ? 0 : intval($_GET['filter_stock']);	// 过滤

	$show = (empty($_GET['show']) || $_GET['show'] > 2) ? 1 : intval($_GET['show']);	// 显示方式


	/* 记录用户 浏览COOKIE */
	wap_setcookie("WAP[cat_id]", 		$cat_id);
	wap_setcookie("WAP[sort]", 			$sort);
	wap_setcookie("WAP[filter_stock]", 	$filter_stock);
	wap_setcookie("WAP[show]", 			$show);


	/* 定义产品图片尺寸 */
	if ($show == 2)
	{
		$pic_format = array('w_h'=>'138x174', 'ratio'=>70);
		$isHD && $pic_format = array('w_h'=>'276x348', 'ratio'=>80);
	}
	else
	{
		$pic_format = array('w_h'=>'90x113', 'ratio'=>70);
		$isHD && $pic_format = array('w_h'=>'180x226', 'ratio'=>80);
	}


	/* 品牌商品列表 */
	$goodslist = get_products_list($brand_id, $cat_id, $sort, $filter_stock);
	//var_dump($goodslist);

	/* 分页 */
	$count = count($goodslist);
	$page > ceil($count/$perpage) && $page = ceil($count/$perpage);

	$params = array(
		'm'			=> 'brand',
		'act'		=> $action,
		'brand_id'	=> $brand_id,
		'cat_id'	=> $cat_id,
		'perpage'	=> $perpage,
		'sort'		=> $sort,
		'filter_stock'	=> $filter_stock,
		'show'		=> $show
	);

	$pager = get_pager('index.php',$params, $count, $page, $perpage ,0);
	$smarty->assign('pager', $pager);

	$goodslist = array_slice($goodslist, ($page-1) * $perpage, $perpage);


	$smarty->assign('brand_id', 			$brand_id);
	$smarty->assign('cat_id', 				$cat_id);

	$smarty->assign('goodslist',       		$goodslist);

	$smarty->assign('sort', 				$sort);
	$smarty->assign('filter_stock', 		$filter_stock);
	$smarty->assign('show', 				$show);

	$smarty->assign('url_here', 			assign_ur_here($model, array('brand_id'=>$brand_id, 'cat_id'=>$cat_id)));

}

$smarty->display('brand_list.dwt');